package com.code.bolg.controller;

import com.code.bolg.bean.Speak;
import com.code.bolg.constant.RedisConstant;
import com.code.bolg.service.SpearkService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 储存在redis中
 */
@Slf4j
@RestController
@RequestMapping("/speark")
public class SpearkController {
    @Autowired
    private SpearkService spearkService;

    @RequestMapping("/saveOrUpdate")
    public Object save(String key, String value) {
        key = RedisConstant.SPEAK;
        return spearkService.save(key, value);
    }

    @RequestMapping("/delete")
    public Object delete(String key) {
        key = RedisConstant.SPEAK;
        return spearkService.delete(key);
    }

    @RequestMapping("/find")
    public Object find(String key) {
        String classPath = Thread.currentThread().getContextClassLoader().getResource("").getPath();
        log.info("classPath:{}",classPath);
        key = RedisConstant.SPEAK;
        Speak speak = new Speak();
        speak.setTitle(spearkService.find(key));
        return  speak;
    }
}
